﻿using EmprestaAE.MVVM.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace EmprestaAE
{
    public class NavigationService
    {
        private static Frame rootFrame;

        private static Frame RootFrame
        {
            get { return rootFrame ?? (rootFrame = (Window.Current.Content as Frame)); }
        }

        private VMCommand navigateCommand;

        public VMCommand NavigateCommand
        {
            get { return navigateCommand ?? (navigateCommand = new VMCommand(NavigateCommandAction)); }
            
        }

        private void NavigateCommandAction(object param)
        {
            if (param == null) return;
            RootFrame.Navigate(param.GetType());
        }

        private VMCommand goBackCommand;

        public VMCommand GoBackCommand
        {
            get { return goBackCommand ?? (goBackCommand = new VMCommand(GoBackCommandAction)); }
            
        }

        private void GoBackCommandAction(object obj)
        {
            if (RootFrame.CanGoBack) RootFrame.GoBack();
        }

        private VMCommand goForwardCommand;

        public VMCommand GoForwardCommand
        {
            get { return goForwardCommand ?? (goForwardCommand = new VMCommand(GoForwardCommandAction)); }            
        }

        private void GoForwardCommandAction(object obj)
        {
            if (RootFrame.CanGoForward) RootFrame.GoForward();
        }
    }
}
